'''
雨滴桌面数据接口
采取(极为高级)的文件传输系统
'''
import os

from configobj import ConfigObj as conf

class Rainmeter:
    def __init__(self, datafile = "./@Resources/data.inc"):
        try:
            self.filehandle = conf(datafile, encoding="GB2312")
            self.data = self.filehandle["Variables"]
        except KeyError:
            with open(datafile, 'w', encoding="GB2312") as f:
                f.write("[Variables]")
            self.filehandle = conf(datafile, encoding="GB2312")
            self.data = self.filehandle["Variables"]

    def __getitem__(self, index):
        return self.data[index]

    def __setitem__(self, index, value):
        self.data[index] = value

    def save(self):
        self.filehandle.write()

    def __del__(self):
        self.save()